package com.qf.config;

import com.qf.task.TestTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 定时任务初始化模板
 * @author 千锋健哥
 */
@Configuration
public class QuartzConfig {

    /**
     * 任务执行详情
     * @return
     */
    @Bean
    public JobDetail jobDetail(){
        return JobBuilder.newJob(TestTask.class)
                .withDescription("这是结合spring boot集成的quartz")
                .withIdentity("spring-boot-quartz")
                .storeDurably() // 当定时任务结束的时候,会存储起来.现在默认的存储的是在: 内存当中.
                .build();
    }

    @Bean
    public Trigger trigger(JobDetail jobDetail){
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail) // 你要执行哪个Job
                .withIdentity("spring-boot-trigger")
                .withDescription("spring boot集成的trigger")
                .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?"))
                .build();
    }
}
